<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('出入库管理')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list" >
                    <ul>
                        <li class="select-time">
                            <span>出入库时间:</span>
                            <input type="text" class="mytime" id="beginTime" placeholder="年/月/日" name="startTime"/>
                            <span>-</span>
                            <input type="text" class="mytime" id="endTime" placeholder="年/月/日" name="endTime"/>
                        </li>
                        <li>
                            类型：
                            <select name="type" th:with="type=${@dict.getType('bus_stock_bill_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            状态：
                            <select name="status" th:with="type=${@dict.getType('bus_stock_bill_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            仓库：
                            <select name="storeId">
                                <option value="">所有</option>
                                <option th:each="store : ${stores}" th:text="${store.storeName}"
                                        th:value="${store.id}"></option>
                            </select>
                        </li>
                        <div>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </div>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="putStore()">
                <i class="fa fa-plus"></i> 入库
            </a>
            <a class="btn btn-warning " id="edit" onclick="outStore()">
                <i class="fa fa-minus"></i> 出库
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<link rel="stylesheet" type="text/css" href="/plugins/datetimepicker/jquery.datetimepicker.min.css"/>
<script src="/plugins/datetimepicker/jquery.datetimepicker.full.js"></script>
<script th:inline="javascript">;

    //企业出入库管理类型
    var stockBillTypeDatas = [[${@dict.getType('bus_stock_bill_type')}]];
    //企业出入库管理状态
    var stockBillStatusDatas = [[${@dict.getType('bus_stock_bill_status')}]];

    var prefix = ctx + "/business/stockBill";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove?id={id}",
            modalName: "出入库管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号',
                    visible: true,
                    formatter:function (value,row,index) {
                        //获取每页显示的数量
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回序号
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(stockBillTypeDatas, value);
                    }
                },
                {
                    field: 'store.storeName',
                    title: '仓库',
                },
                {
                    field: 'totalAmounts',
                    title: '总数量',
                },
                {
                    field: 'totalPrice',
                    title: '总金额',
                },
                {
                    field: 'user.userName',
                    title: '录入人',
                },
                {
                    field: 'busiDate',
                    title: '出入库时间',
                },
                {
                    field: 'operateDate',
                    title: '录入时间',
                },
				{
					field:'status',
					title:'状态',
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(stockBillStatusDatas, value);
					}
				},
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var removeClass = '';
                        if (row.status==-1){
                            removeClass = "disabled";
                        }
                        actions.push('<a class="btn btn-info '+removeClass+' btn-xs " href="javascript:void(0)" ' +
                            'onclick="remove(\'' + row.id + '\')"><i class="fa fa-edit"></i>作废</a> ');

                        actions.push('<a class="btn btn-success  btn-xs " href="javascript:void(0)" ' +
                            'onclick="details(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function details(id) {
        $.modal.open("仓库明细","/business/stockBillItem/listPage?id="+id);
    }

    function remove(id) {
        $.operate.remove(id);
    }

    function putStore(){
        $.modal.openTab("入库操作","/business/stockBill/putStore");
    }

    function outStore(){
        $.modal.openTab("出库操作","/business/stockBill/outStore");
    }


$('.mytime').datetimepicker({
    format:'Y-m-d'
});
$.datetimepicker.setLocale('zh');

</script>
</body>
</html>